package com.conexion;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.view.Gravity;
import android.widget.Toast;

public class Utilitario extends Activity{

	private Pattern pattern;
	private Matcher matcher;
 
	private static final String EMAIL_PATTERN = 
		"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
		+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
 
	public Utilitario() {
		
		pattern = Pattern.compile(EMAIL_PATTERN);
	
	}
	
	public boolean validate(final String hex) {
		 
		matcher = pattern.matcher(hex);
		return matcher.matches();
 
	}	
	
	public static boolean hasInternet(Activity a) { 
		boolean hasConnectedWifi = false; 
		boolean hasConnectedMobile = false; 

		ConnectivityManager cm = (ConnectivityManager) a.getSystemService(Context.CONNECTIVITY_SERVICE); 
		NetworkInfo[] netInfo = cm.getAllNetworkInfo(); 
		for (NetworkInfo ni : netInfo) { 
		if (ni.getTypeName().equalsIgnoreCase("wifi")) 
		if (ni.isConnected()) 
		hasConnectedWifi = true; 
		if (ni.getTypeName().equalsIgnoreCase("mobile")) 
		if (ni.isConnected()) 
		hasConnectedMobile = true; 
		} 
		return hasConnectedWifi || hasConnectedMobile; 
		}

	
		public void mensaje(String mensaj, Activity activity ){
			
			Toast td = Toast.makeText(activity, mensaj, Toast.LENGTH_LONG);
			td.setGravity(Gravity.CENTER, 0, 0);
			td.show();
		}
		
}
